import { find, ScrollView } from 'cc';
import { _decorator, Component, Node, Label, tween, view, UITransform, Vec3, SpriteAtlas, SpriteFrame, Sprite, UIOpacity, EventTouch, Toggle, Prefab, instantiate } from 'cc';
import { App } from '../../App';
import { localKey } from '../../common/Common';
import { PD } from '../../player/PlayerData';
import { LoadMg } from '../../tools/LoadMg';
import UtilTool from '../../tools/UtilTool';
const { ccclass, property } = _decorator;

// 幸运球规则界面
@ccclass('LBRulePanel')
export class LBRulePanel extends Component {
    @property(ScrollView)
    scroll: ScrollView = null;

    @property(Node)
    content: Node = null;

    @property(Node)
    item1: Node = null;

    @property(Node)
    item2: Node = null;

    @property(Node)
    item3: Node = null;

    @property(Node)
    item4: Node = null;

    @property(Node)
    item5: Node = null;

    onLoad() {
        UtilTool.setScreen(this.node)
    }

    start() {
        UtilTool.nodeActive(find("contentNode",this.node),5,0.16)

        // 内容
        let mes1 = find("mes",this.item1).getComponent(Label)
        let mes2 = find("mes",this.item2).getComponent(Label)
        let mes3 = find("mes",this.item3).getComponent(Label)
        let mes4 = find("mes",this.item4).getComponent(Label)
        let mes5 = find("mes",this.item5).getComponent(Label)

        // 设置内容
        let allTime:number = PD.gameConfig.buyTime + PD.gameConfig.countDownTime + PD.gameConfig.hitTime
        // allTime = allTime / 60 // 转化为分钟
        // let buyTime_f = PD.gameConfig.buyTime / 60
        // let hitTime_f = PD.gameConfig.hitTime / 60

        // allTime = allTime // 秒
        let buyTime_f = PD.gameConfig.buyTime // 秒
        let hitTime_f = PD.gameConfig.hitTime // 秒

        mes1.string = App.language.getLanguageLab(91).replace("&", buyTime_f.toString())
        mes2.string = UtilTool.formatStr(App.language.getLanguageLab(155), "1:" + PD.gameConfig.baseOdds, "1:" + PD.gameConfig.hitOdds)
        mes3.string = App.language.getLanguageLab(92).replace("&", allTime.toString())
        mes4.string = App.language.getLanguageLab(93).replace("&", hitTime_f.toString())
        mes5.string = App.language.getLanguageLab(94)

        // 设置高度
        setTimeout(()=>{
            let item1_H = 67 + mes1.node.getComponent(UITransform).contentSize.height + 50
            let item2_H = 67 + mes2.node.getComponent(UITransform).contentSize.height + 50
            let item3_H = 67 + mes3.node.getComponent(UITransform).contentSize.height + 50
            let item4_H = 67 + mes4.node.getComponent(UITransform).contentSize.height + 50
            let item5_H = 67 + mes5.node.getComponent(UITransform).contentSize.height + 50
            this.item1.getComponent(UITransform).setContentSize(800,item1_H)
            this.item2.getComponent(UITransform).setContentSize(800,item2_H)
            this.item3.getComponent(UITransform).setContentSize(800,item3_H)
            this.item4.getComponent(UITransform).setContentSize(800,item4_H)
            this.item5.getComponent(UITransform).setContentSize(800,item5_H)

            let allH = item1_H + item2_H + item3_H + item4_H + item5_H
            let scrollH = 1300
            if (scrollH<allH) {
                scrollH = allH
            }
            this.content.getComponent(UITransform).setContentSize(this.content.getComponent(UITransform).contentSize.width, scrollH)

            this.item1.setPosition(0,scrollH)
            this.item2.setPosition(0,scrollH-item1_H)
            this.item3.setPosition(0,scrollH-item1_H-item2_H)
            this.item4.setPosition(0,scrollH-item1_H-item2_H-item3_H)
            this.item5.setPosition(0,scrollH-item1_H-item2_H-item3_H-item4_H)

            this.scroll.scrollToTop()
        },100)
    }

    /** 
     * 关闭
      */
    clickClose() {
        App.Audio.playOneShot("click")
        this.node.destroy();
    }

}

